package top.mccat.common.core.controller.bk;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mccat.common.annotation.Log;
import top.mccat.common.core.controller.BaseController;
import top.mccat.common.core.domain.AjaxResult;
import top.mccat.common.core.domain.bk.BkBase;
import top.mccat.common.enums.BusinessType;
import top.mccat.common.service.IBkBaseService;
import top.mccat.common.utils.poi.ExcelUtil;
import top.mccat.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author Raven
 * @date 2023-01-09
 */
@RestController
@RequestMapping("/bk/base")
public class BkBaseController extends BaseController
{
    @Autowired
    private IBkBaseService bkBaseService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('bk:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(BkBase bkBase)
    {
        startPage();
        List<BkBase> list = bkBaseService.selectBkBaseList(bkBase);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('bk:base:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkBase bkBase)
    {
        List<BkBase> list = bkBaseService.selectBkBaseList(bkBase);
        ExcelUtil<BkBase> util = new ExcelUtil<BkBase>(BkBase.class);
        util.exportExcel(response, list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(bkBaseService.selectBkBaseById(id));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('bk:base:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkBase bkBase)
    {
        return toAjax(bkBaseService.insertBkBase(bkBase));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('bk:base:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkBase bkBase)
    {
        return toAjax(bkBaseService.updateBkBase(bkBase));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('bk:base:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(bkBaseService.deleteBkBaseByIds(ids));
    }
}
